package cn.lrwjz.androidguide.ui;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.button.MaterialButtonToggleGroup;

import cn.lrwjz.androidguide.R;

/**
 * 按钮示例Activity
 * 展示Material Design按钮组件的使用方法
 */
public class ButtonsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_buttons);

        // 设置工具栏
        MaterialToolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setTitle("Button 示例");
        }

        // 设置悬浮按钮点击事件
        MaterialButton btnElevated = findViewById(R.id.btnElevated);
        MaterialButton btnElevatedIcon = findViewById(R.id.btnElevatedIcon);
        
        btnElevated.setOnClickListener(v -> 
            showToast("点击了悬浮按钮"));
        
        btnElevatedIcon.setOnClickListener(v -> 
            showToast("点击了带图标的悬浮按钮"));

        // 设置实心按钮点击事件
        MaterialButton btnContained = findViewById(R.id.btnContained);
        MaterialButton btnContainedIcon = findViewById(R.id.btnContainedIcon);
        
        btnContained.setOnClickListener(v -> 
            showToast("点击了实心按钮"));
        
        btnContainedIcon.setOnClickListener(v -> 
            showToast("点击了带图标的实心按钮"));

        // 设置色调按钮点击事件
        MaterialButton btnTonal = findViewById(R.id.btnTonal);
        MaterialButton btnTonalIcon = findViewById(R.id.btnTonalIcon);
        
        btnTonal.setOnClickListener(v -> 
            showToast("点击了色调按钮"));
        
        btnTonalIcon.setOnClickListener(v -> 
            showToast("点击了带图标的色调按钮"));

        // 设置描边按钮点击事件
        MaterialButton btnOutlined = findViewById(R.id.btnOutlined);
        MaterialButton btnOutlinedIcon = findViewById(R.id.btnOutlinedIcon);
        
        btnOutlined.setOnClickListener(v ->
            showToast("点击了描边按钮"));
        
        btnOutlinedIcon.setOnClickListener(v -> 
            showToast("点击了带图标的描边按钮"));

        // 设置文本按钮点击事件
        MaterialButton btnText = findViewById(R.id.btnText);
        MaterialButton btnTextIcon = findViewById(R.id.btnTextIcon);
        
        btnText.setOnClickListener(v -> 
            showToast("点击了文本按钮"));
        
        btnTextIcon.setOnClickListener(v -> 
            showToast("点击了带图标的文本按钮"));

        // 设置图标按钮点击事件
        MaterialButton btnIconStandard = findViewById(R.id.btnIconStandard);
        MaterialButton btnIconFilled = findViewById(R.id.btnIconFilled);
        MaterialButton btnIconFilledTonal = findViewById(R.id.btnIconFilledTonal);
        MaterialButton btnIconOutlined = findViewById(R.id.btnIconOutlined);
        
        btnIconStandard.setOnClickListener(v -> 
            showToast("点击了标准图标按钮"));
        
        btnIconFilled.setOnClickListener(v -> 
            showToast("点击了填充图标按钮"));
        
        btnIconFilledTonal.setOnClickListener(v -> 
            showToast("点击了色调图标按钮"));
        
        btnIconOutlined.setOnClickListener(v -> 
            showToast("点击了描边图标按钮"));

        // 设置分段按钮组选择事件
        MaterialButtonToggleGroup toggleButton = findViewById(R.id.toggleButton);
        toggleButton.addOnButtonCheckedListener((group, checkedId, isChecked) -> {
            if (isChecked) {
                String option = "";
                if (checkedId == R.id.btnSegment1) {
                    option = "一";
                } else if (checkedId == R.id.btnSegment2) {
                    option = "二";
                } else if (checkedId == R.id.btnSegment3) {
                    option = "三";
                }
                showToast("选择了选项" + option);
            }
        });
    }

    private void showToast(String message) {
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
} 